using System;
using System.Collections.Generic;
using Entitas;

public sealed class DestroyViewSystem : ReactiveSystem {

    public DestroyViewSystem(Contexts contexts) : base(contexts.core)
    {
    }


    protected override void Execute(List<Entity> entities) {
        foreach(var e in entities) {
            var controller = e.view.controller;
            if (controller is IPoolableViewController)
                controller.Hide(true);
            else if (controller is IViewController)
                Assets.Destroy(controller.gameObject);
        }
    }

    protected override Collector GetTrigger(Context context)
    {
        return context.CreateCollector(Matcher.AllOf(CoreMatcher.View, CoreMatcher.Destroy));
    }

    protected override bool Filter(Entity entity)
    {
        return true;
    }
}
